package com.mediacloud.app.newsmodule.activity.military_encyclopedia

import android.graphics.Color
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.jaeger.library.StatusBarUtil
import com.mediacloud.app.assembly.util.loadX
import com.mediacloud.app.model.activity.BaseBackActivity
import com.mediacloud.app.newsmodule.R
import com.yoake.media.player.XPlayer
import kotlinx.android.synthetic.main.activity_video_play.*
import xyz.doikki.videoplayer.player.BaseVideoView
import xyz.doikki.videoplayer.player.VideoView

class WikiVideoPlayActivity : BaseBackActivity() {


    override fun getContent_show_top_color(): String {
        return "#FFFFFF"
    }

    override fun getFitSystemWindow(): Boolean {
        return false
    }


    override fun getStatusBarColor(): Int {
        return Color.TRANSPARENT
    }

    fun initDataView() {
        val url = intent.getStringExtra("playUrl")
        val logo = intent.getStringExtra("logo")
        val duration = intent.getStringExtra("Duration")
        poster.loadX(logo,3,0,false)
        tvNewsTip.text = duration
        ivVideo.setOnClickListener { player.start() }
        player.setPlayerType(XPlayer.VIDEO_VOD)
        player.hideTitleLayoutWhenInNormalState()
        player.setUrl(url)
        player.start()
        player.setOnStateChangeListener(object :BaseVideoView.OnStateChangeListener{
            override fun onPlayerStateChanged(playerState: Int) {
                val isFullScreen = playerState == VideoView.PLAYER_FULL_SCREEN

            }

            override fun onPlayStateChanged(playState: Int) {
                when (playState){
                    VideoView.STATE_ERROR->{
                        logoLayout.visibility = View.GONE
                    }
                    VideoView.STATE_PREPARED->{
                        logoLayout.visibility = View.GONE
                    }
                    VideoView.STATE_PLAYBACK_COMPLETED->{
                        logoLayout.visibility = View.VISIBLE
                    }
                }
            }

        })
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mRootView.setBackgroundColor(Color.BLACK)
        val lp = ivBack.layoutParams as ViewGroup.MarginLayoutParams
        lp.topMargin = StatusBarUtil.getStatusBarHeight(this)
        ivBack.layoutParams = lp
        findViewById<ImageView>(R.id.ivBack).setOnClickListener { finish() }
        initDataView()
    }

    override fun getLayoutResID(): Int {
       return R.layout.activity_video_play
    }
}